/**
 * 部门js
 */
var orderAbnormal = {
	curPage : 0,
	pageSize : 100,
	dataCache : null,
	 

	startEvent : function() {
		// 按回车键登录事件
		document.onkeydown = function(e) {
			var ev = document.all ? window.event : e;
			if (ev.keyCode == 13) {
				orderAbnormal.curPage = 1;
				orderAbnormal.setPageChange(null);
				orderAbnormal.search();
			}
		};
	},
	
	getResource : function() {
		var url = 'mgr/ProductInfoCtrl/getProductInfoList';
		var params = {
			'curPage' : 1,
			'pageSize' : 9999,
		};
		var cb = function(data) {
			if (data.resultCode == 200) {
				var option = '<option value="">请选择产品名称</option>';
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					option = option + '<option value="' + singleObj.id + '">'
							+ singleObj.name + '</option>';
				}
				$('select[name="productId"]').append(option);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},

	bindEvent : function() {
		
	},

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/orderCheck/getList';
		if (typeof (pageIdx) != "undefined") {
			orderAbnormal.curPage = pageIdx;
		}

		var params = {
			'curPage' : orderAbnormal.curPage,
			'pageSize' : orderAbnormal.pageSize
		};


		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / orderAbnormal.pageSize > 0) ? Math
						.ceil(totalCount / orderAbnormal.pageSize) : 1;
				
				var delCurPage = 1;
				pageHelper.init(pageTotal, totalCount, orderAbnormal.search,
						delCurPage); // 翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},

	// 查询交易记录
	search : function(pageIdx) {
		var url = 'mgr/orderCheck/getList';
		if (typeof (pageIdx) != "undefined") {
			orderAbnormal.curPage = pageIdx;
		}

		var params = {
			'curPage' : orderAbnormal.curPage,
			'pageSize' : orderAbnormal.pageSize
		};

		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';
			if (data.result != null && data.result.length > 0) {
				for (var i = 0; i < data.result.length; i++) {

					var singleObj = data.result[i];
					
					var orderCreatedOn = getSmpFormatDateByLong(singleObj.cts,
							true);
					
					tr += '<tr><td><input type="hidden" name="orderId" value="'
							+ singleObj.orderId
							+ '"/>'
							+ (i + 1)
							+ '</td><td>'
							+ singleObj.orderId
							+ '</td><td>'
							+ singleObj.amount
							+ '</td><td>'
							+ singleObj.payStatus
							+ '</td><td>'
							+ singleObj.confirmStatus
							+ '</td><td>'
							+ singleObj.userName
							+ '</td><td>'
							+ singleObj.userPhoneNum
							+ '</td><td>'
							+ singleObj.productId
							+ '</td><td>'
							+ singleObj.productName
							+ '</td><td>'
							+ singleObj.companyName
							+ '</td><td>'
							+ orderCreatedOn
							+ '</td><td>'
							+ '<a type="button" name="orderRecheck_102" class="btn btn-primary btn-xs orderRecheck"  style="margin-left: 5px;">'
							+ '<i class="fa fa-reorder"></i> 刷新订单 </a>'
							+ '</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="6" style="text-align: center;color: red;">暂无数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			orderAbnormal.bindEventOtherBtn();
			jsUtils.controlFunctionBtn();
		};

		sendApiNoLoad(url, params, cb, 'POST');
	},

	bindEventOtherBtn : function() {
		$('.orderRecheck').on('click', function() {
			var url = 'mgr/orderCheck/reCheck';
			if (typeof (pageIdx) != "undefined") {
				orderAbnormal.curPage = pageIdx;
			}

			var orderId = $("input[name='orderId']").val(); 
			var params = {
				'orderId':orderId
			};
			var cb = function(data) {
				if (data.resultCode == 200) {
					var totalCount = data.size;
					var pageTotal = (totalCount / orderAbnormal.pageSize > 0) ? Math
							.ceil(totalCount / orderAbnormal.pageSize) : 1;
					
					var delCurPage = 1;
					pageHelper.init(pageTotal, totalCount, orderAbnormal.search,
							delCurPage); // 翻页事件
					
					orderAbnormal.setPageChange(null);
				}
			};
			sendApiNoLoad(url, params, cb, 'POST');
		}); 
		
	},

	init : function() {
		orderAbnormal.setPageChange(null);
		orderAbnormal.search();
		orderAbnormal.startEvent();
		orderAbnormal.bindEvent();
	}
};

$(document).ready(function() {
	orderAbnormal.init();
});

//提供给外部刷新调用
function refashData() {
	orderAbnormal.setPageChange(null);
	orderAbnormal.search();
}

 


